package com.info.zhiduoduo.common.exception;

import com.info.zhiduoduo.common.constants.StatusMsg;

import java.util.List;

import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;

@Data
@Accessors(chain = true)
@EqualsAndHashCode(callSuper = true)
public class SmartException extends RuntimeException {

	protected int state = StatusMsg.StatusMsg_198.getState();
	protected String msg = StatusMsg.StatusMsg_198.getMsg();
	protected Object data;
	protected List<?> list;

	public SmartException() {
		super(StatusMsg.StatusMsg_198.getMsg());
	}

	public SmartException(String message) {
		super(message);
	}

	public SmartException(String message, Throwable cause) {
		super(message, cause);
	}

	public SmartException(int state, String msg) {
		super(msg);
		this.state = state;
		this.msg = msg;
	}

	public SmartException(int state, String msg, Object data) {
		super(msg);
		this.state = state;
		this.msg = msg;
		this.data = data;
	}

	public SmartException(StatusMsg statusMsg) {
		super(statusMsg.getMsg());
		this.state = statusMsg.state;
		this.msg = statusMsg.msg;
	}

	public SmartException(StatusMsg statusMsg, Object data) {
		super(statusMsg.getMsg());
		this.state = statusMsg.state;
		this.msg = statusMsg.msg;
		this.data = data;
	}

	public SmartException(StatusMsg statusMsg, List<?> list) {
		super(statusMsg.getMsg());
		this.state = statusMsg.state;
		this.msg = statusMsg.msg;
		this.list = list;
	}

	public SmartException(StatusMsg statusMsg, Throwable cause) {
		super(statusMsg.getMsg(), cause);
		this.state = statusMsg.state;
		this.msg = statusMsg.msg;
	}

	public static SmartException of() {
		return new SmartException();
	}

	public static SmartException of(String msg) {
		return new SmartException().setMsg(msg);
	}

	public static SmartException of(int state, String msg) {
		return new SmartException(state, msg, null);
	}

	public static SmartException of(int state, String msg, Object data) {
		return new SmartException(state, msg, data);
	}

	public static SmartException of(StatusMsg statusMsg) {
		return of(statusMsg.getState(), statusMsg.getMsg());
	}

	public static SmartException of(StatusMsg statusMsg, Object data) {
		return of(statusMsg).setData(data);
	}

	public static SmartException of(StatusMsg statusMsg, Throwable cause) {
		SmartException smartException = new SmartException(statusMsg, cause);
		return smartException;
	}

	public static SmartException of(StatusMsg statusMsg, Object data, Throwable cause) {
		SmartException smartException = new SmartException(statusMsg, cause);
		smartException.setData(data);
		return smartException;
	}

	public static SmartException of(int state, String msg, Object data, Throwable cause) {
		SmartException smartException = new SmartException(msg, cause);
		smartException.setState(state);
		smartException.setMsg(msg);
		smartException.setData(data);
		return smartException;
	}

	public static void throwOf() {
		throw of();
	}

	public static void throwOf(String msg) {
		throw of(msg);
	}

	public static void throwOf(int state, String msg) {
		throw of(state, msg);
	}

	public static void throwOf(int state, String msg, Object data) {
		throw of(state, msg, data);
	}

	public static void throwOf(StatusMsg statusMsg) {
		throw of(statusMsg);
	}

	public static void throwOf(StatusMsg statusMsg, Object data) {
		throw of(statusMsg, data);
	}
}
